/********************init.htm**************/
/*function queryOrgan(page) {
	var parm = $('#queryOrganForm').serialize() + sys_get_page(page);
	var url = create_url('organn-query');
	sys_record_parm('organn', parm);
	sys_loading();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_loading_close();
			$('#resultList').html(result);
		}
	});
}

function deleteOrgan(code, name) {
	var url = create_url('organn-delete');
	aidExecuteOrgan(code, url);
}

function shieldOrgan(code, name) {
	sys_msg('确认要屏蔽 ' + name + ' 机构的信息吗？', { 
		buttons:{'确认删除':true, '取消':false},
		close: function(e, v, m, f) {
			if (v) {
				var url = create_url('organ-shield');
		    	aidExecuteOrgan(code, url);
			}
		}
	});
}


function unshieldOrgan(code, name) {
	sys_msg('确认要解除 ' + name + ' 机构的屏蔽状态吗？', { 
		buttons:{'确认解除':true, '取消':false},
		close: function(e, v, m, f) {
			if (v) {
		    	var url = create_url('organn-unshield');
		    	aidExecuteOrgan(code, url);
			}
		}
	});
}

function aidExecuteOrgan(code, url) {
	var parm = {'code':code};
	sys_submiting();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_submiting_close();
			if ('success' == result) {
				jConfirm('操作成功', '提示', function(r) {
					if(r == true){
						var url = create_url('organ-shield');
						organ_aidExecuteOrgan(code, url);
					}
				});
				sys_msg('操作成功!');
				queryOrgan();
			} else {
				sys_warning('操作失败', '操作失败，请刷新页面再次尝试，如果问题依然存在，请联系管理员!');
			}
		}
	});
}

function selectParent() {
	var url = create_url('organn-aidQueryInit');
	var parm = {'id':'parentCode', 'name':'parentName'};
	$.colorbox({overlayClose:false, href:url, data:parm, close:'[关闭]', width:'800px', height:'600px', open:true});
}

function loadSonList(code) {
	var url = create_url('organn-sonList');
	var parm = {'code':code};
	var sonTd = $('#orgaSonTd_' + code);
	sonTd.html(sys_loading_img);
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sonTd.html(result);
		}
	});
}

function editOrgan(code, parentCode) {
	var url = create_url('organn-edit');
	var parm = {'code':(null != code ? code : ''), 'parentCode':(null != parentCode ? parentCode : '')};
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			$('#editOrganTd').html(result);
		}
	});
}*/
/***********edit.html****************/

function selectParent() {
	var url = create_url('organn-aidInit');
	var parm = {'id':'pc', 'name':'pn'};
	$.colorbox({overlayClose:false, href:url, data:parm, close:'[关闭]', width:'400px', height:'600px', open:true});
}

function addFilesUploadEvent(id, contextPath) {
	var url = create_url('organOrgan-uploads');
	var btn = $('#uploadFilesBtn' + id);
	new AjaxUpload(btn, {
		action:url,
		name:'files',
		multiple: true,
		responseType: 'json',
		onSubmit : function(file, ext) {
			if (ext && /^(jpg|png|jpeg|gif|bmp|JPG|PNG|JPEG|GIF|BMP)$/.test(ext)){
				this.setData({'info':'文件类型正确'});
			} else {
				sys_msg('文件类型错误', '只能上传类型为：jpg、png、jpeg、gif、bmp、图片文件!尺寸小于300*300最佳');
				return false;               
			}
			$('#upload_span').html(sys_loading_img);
			this.disable();
		},
		onComplete: function(files, response){
			if ('error' == response.result)
				sys_msg('失败', '上传文件失败，请检查文件名是否正确!');
			else if ('file_type_error' == response.result)
				sys_msg('文件类型错误', '只能上传类型为：jpg、png、jpeg、gif、bmp、图片文件!');
			else {
				console.log(id +"a");
				if(id == 4){
					console.log(id);
					var template = $('#tempAnnexListDiv' + id).find('.rep');
				}else{
					var template = $('#tempAnnexListDiv').find('.rep');
				}
				var annexList = $('#annexListTable'+ id);
				var index = parseInt($('#organOrgan_an_index').val());
				$.each(response.list, function(i) {
					var pii = template.clone(true);
					pii.find('.title').html(response.list[i].name).end()
						.find('.imgs').attr('src',contextPath+response.list[i].path).end()
						.find('.name').attr('name', 'List[' + index + '].name').val(response.list[i].name).end()
						.find('.size').attr('name', 'List[' + index + '].size').val(response.list[i].size).end()
						.find('.sn').attr('name', 'List[' + index + '].sn').val(response.list[i].path).end()
						.find('.ext').attr('name', 'List[' + index + '].ext').val(response.list[i].ext).end()
						.find('.cover').attr('name', 'List[' + index + '].cover').val('false').end()
						.find(".type").attr({"name": "List[" + index + "].type"}).val(id).end()
						.find('.afcs').val(response.list[i].code).end();
					annexList.append(pii);
					index ++;
				});
				this.enable();
				$('#organOrgan_an_index').val(index);
			}
		}
	});
}

function deleteSelectedItem(btn) {
	btn.parents('.rep').remove();
}

function saveOrgan() {
	var parm = $('#editOrganForm').serialize() + '&synopsis.content=' + fixJqText(Url.encode(content.getData()));
	var url = create_url('organOrgan-save');
	sys_submiting();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_submiting_close();
			if (result == 'success') {
				sys_msg('操作成功!');
				sys_load_handle('organOrgan');
			} else if (result == 'parameter_error') {
				sys_msg('父机构不能为空!');
			} else if (result == 'failure') {
				sys_msg('父机构不能选择自己!');
			} else {
				sys_msg('操作失败!');
			}
		}
	});
}

function selectParent(code) {
	var url = create_url('organOrgan-aidInit');
	var parm = {'id':'pc', 'name':'pn', 'code':code};
	$.colorbox({overlayClose:false, href:url, data:parm, close:'[关闭]', width:'400px', height:'600px', open:true});
}

//异步加载
function loadScript() {
	var script = document.createElement("script");
	script.type = "text/javascript";
	script.src = "http://webapi.amap.com/maps?v=1.3&key=yourkey&callback=init";
	document.body.appendChild(script);
}


function clickGetPoits_organOrgan(lo,la){
	map.clearMap();
	marker = new AMap.Marker({     
     });     
	marker.setMap(map); 
	marker.setPosition(new AMap.LngLat(parseFloat(lo),parseFloat(la)));
	
	crawlPoint_organOrgan();
}

function crawlPoint_organOrgan(){
	var lo = $("#lo").val();  
	var la = $("#la").val(); 
	$("#longitude").val(lo);  
	$("#latitude").val(la); 
}